/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package frmsystem;

import java.util.ArrayList;
import java.util.Observable;

/**
 *
 * @author imran
 */
public abstract class Party implements IParty {
	
	private String name;
	private String street;
	private String city;
	private String state;
	private String zip;
	private String email;
	private int type;

	//TODO add a list of IAccount here : Nuwan
	private ArrayList<IAccount> accounts;	
	
	
    public Party() {
		this.accounts =  new ArrayList<IAccount>();
	}

	public String getCity() {
        return this.city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getState() {
        return this.state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getStreet() {
        return this.street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getZip() {
        return this.zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }
    
    /**
     * This function adds a new account to the accounts arraylist
     */
    public void openAccount(IAccount account){
    	//TODO use assert to check if incoming object is valid
    	this.accounts.add(account);
    }      

    /**
     * This function closes ie removes an account which matches
     * the account number provided from the arraylist of accounts
     */
    public void closeAccount(String accountNo){
    	if (!accountNo.isEmpty()) {
    		for(IAccount account:this.accounts) {
    			if(account.getAccountNo().equals(accountNo)) {
    				this.accounts.remove(account);
    			}
    		}
    	}
    }  

    /**
     * This method generates a email to the party with the said msg
     */
    public void generateEmail(String subject, String msg){
    	/*Emailer emailer = new Emailer();
    	String[] recipient = {email};    	
    	emailer.SendEmail(recipient, subject, msg);*/
    }

    //public void applyInterest(){}   //TODO since now we have a list of accounts in the domain class this method might not be needed : Nuwan

    @Override
	public abstract void update(Observable arg0, Object arg1);

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public ArrayList<IAccount> getAccounts() {
		return accounts;
	}
    
    

}
